public class Demo {//懒汉模式
    public static volatile Demo instance = null;//防止指令重排序
    private Demo(){ }
    public static Demo getInstance(){
        if(instance == null){//判断是否加锁
            synchronized (Demo.class){
                if(instance == null){//判断是否为null
                    instance = new Demo();
                }
            }
        }
        return instance;
    }
}
class Singleton{
    private static Singleton instance = new Singleton();
    private Singleton(){

    }
    public Singleton getInstance(){
        return instance;
    }
}
